#include "viewcontactdialog.h"

ViewContactDialog::ViewContactDialog(QWidget *parent, Qt::WFlags f)
    : QWidget(parent, f)
{
    // initialize the dialog
	setupUi(this);
}

ViewContactDialog::~ViewContactDialog()
{
    // Do nothing
}

void ViewContactDialog::setupView(int index, NeoPhoneBookEntry *entry)
{    
	phoneBookIndex = index;
	nameLabel->setText(entry->getContactName());
	numberLabel->setText(entry->getPhoneNumber());
	emailLabel->setText(entry->getContactEmail());
	QString pictureFilePath = entry->getPictureFilePath();
	if (!pictureFilePath.isEmpty()) {
		QPixmap pixmap(pictureFilePath);
		if (!pixmap.isNull()) {
			pixmap = pixmap.scaled(QSize(pictureLabel->width(), 
					 pictureLabel->height()), Qt::KeepAspectRatio, 
					 Qt::SmoothTransformation);
			pictureLabel->setPixmap(pixmap);
		}
	}
}

void ViewContactDialog::on_editPushButton_clicked()
{
	emit editContactSignal(phoneBookIndex);
	close();
}
void ViewContactDialog::on_deletePushButton_clicked()
{
	QMessageBox msgBox;
    msgBox.setWindowTitle("Delete Contact");
    msgBox.setIcon(QMessageBox::Information);
    msgBox.setText("Do you really want to do that?");
    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);	
	
    switch (msgBox.exec()) {	
    case QMessageBox::Yes:
		emit deleteContactSignal(phoneBookIndex);
		close();
		break;
    case QMessageBox::No:
        break;
    default:
        break;
    }	
}
void ViewContactDialog::on_callPushButton_clicked()
{
	qDebug() << "I said DO NOT CALL ME ...";
}

